﻿using System;
using System.Collections.Generic;


namespace ExtensibleEventViewer.Console.Forms
{
	public partial class ComputerListWnd : FormBase
	{
		public Action<IEnumerable<string>> SaveComputerList;

		public ComputerListWnd()
		{
			InitializeComponent();
		}

		public ComputerListWnd(IEnumerable<string> computerNames)
		{
			InitializeComponent();

			computerListControl.ComputerNames = computerNames;
		}

		private void CancelClick(object sender, EventArgs e)
		{
			Close();
		}

		private void SaveClick(object sender, EventArgs e)
		{
			if (SaveComputerList != null)
			{
				SaveComputerList(computerListControl.ComputerNames);
			}

			Close();
		}

		private void AddComputerClick(object sender, EventArgs e)
		{
			using (AddComputerWnd addComputerWnd = new AddComputerWnd())
			{
				addComputerWnd.AddComputer += AddComputerIntoList;

				addComputerWnd.ShowDialog(this);
			}
		}

		private void AddComputerIntoList(string computerName)
		{
			computerListControl.AddComputer(computerName);
		}

		private void DeleteSelectedItemsClick(object sender, EventArgs e)
		{
			computerListControl.DeleteSelectedComputernames();
		}
	}
}
